package com.kotlin.zds

import android.view.LayoutInflater
import android.view.View
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import com.kotlin.zds.base.BaseActivity
import com.kotlin.zds.databinding.ActivityMainBinding
import com.kotlin.zds.databinding.ActivityWelcomBinding
import com.xuexiang.xui.utils.StatusBarUtils

/**
 * Author: zds
 * Date: 2022/6/10 18 03
 * Description:
 * Version: v1.0
 */
class MainActivity : BaseActivity(){
    private var lastIndex=-1
    private val navController : NavController by lazy {
        val navHost = supportFragmentManager.findFragmentByTag("my_tag") as NavHostFragment
        navHost.navController
    }

    val viewBinding by lazy {
        ActivityMainBinding.inflate(LayoutInflater.from(mActivity))
    }
    override fun onSetContentView() {
        StatusBarUtils.initStatusBarStyle(this,false)
        setContentView(viewBinding.root)
    }

    override fun initView() {
        selectTab(0)
        viewBinding.run {
           tabHome.setOnClickListener(mOnClickListener)
            tabTask.setOnClickListener(mOnClickListener)
            tabMy.setOnClickListener(mOnClickListener)
        }
    }

    fun selectTab(position:Int){
        if (position!=lastIndex){
            if(lastIndex!=-1){
                viewBinding.tabGroup.getChildAt(lastIndex).isSelected=false
            }
            viewBinding.tabGroup.getChildAt(position).isSelected=true
            lastIndex=position
        }
    }


    override fun initData() {

    }

    override fun onViewClick(v: View) {
        when(v){
            viewBinding.tabHome->{
                selectTab(0)
                navController.navigate(R.id.navigation_home)
            }
            viewBinding.tabTask->{
                selectTab(1)
                navController.navigate(R.id.navigation_jd)
            }
            viewBinding.tabMy->{
                selectTab(2)
                navController.navigate(R.id.navigation_mine)
            }
        }
    }
}